mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
remove reddit system
jraw free 🦀🦀🦀
This commit is contained in:
parent
c8ec171b11
commit
de496970d9
15
pom.xml
15
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2020.11.5</version>
|
||||
<version>2020.12</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
<name>TotalFreedomMod</name>
|
||||
<description>Server modification for the TotalFreedom server</description>
|
||||
<url>https://github.com/TFPatches/TotalFreedomMod</url>
|
||||
<url>https://github.com/AtlasMediaGroup/TotalFreedomMod</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
@ -202,7 +202,7 @@
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.2.0_222</version>
|
||||
<version>4.2.0_223</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -223,7 +223,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.5</version>
|
||||
<version>1.0.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -275,13 +275,6 @@
|
||||
<version>3.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dean.jraw</groupId>
|
||||
<artifactId>JRAW</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,217 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
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.dean.jraw.ApiException;
|
||||
import net.dean.jraw.RedditClient;
|
||||
import net.dean.jraw.http.OkHttpNetworkAdapter;
|
||||
import net.dean.jraw.http.UserAgent;
|
||||
import net.dean.jraw.models.CurrentFlair;
|
||||
import net.dean.jraw.models.Flair;
|
||||
import net.dean.jraw.oauth.Credentials;
|
||||
import net.dean.jraw.oauth.OAuthHelper;
|
||||
import net.dean.jraw.references.SubredditReference;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Reddit extends FreedomService
|
||||
{
|
||||
private final String SUBREDDIT_NAME = ConfigEntry.REDDIT_SUBREDDIT_NAME.getString();
|
||||
private final String USERNAME = ConfigEntry.REDDIT_USERNAME.getString();
|
||||
private final String PASSWORD = ConfigEntry.REDDIT_PASSWORD.getString();
|
||||
private final String CLIENT_ID = ConfigEntry.REDDIT_CLIENT_ID.getString();
|
||||
private final String CLIENT_SECRET = ConfigEntry.REDDIT_CLIENT_SECRET.getString();
|
||||
|
||||
private final UserAgent userAgent = new UserAgent("bot", "me.totalfreedom.reddit", TotalFreedomMod.build.version, USERNAME);
|
||||
private final Credentials credentials = Credentials.script(USERNAME, PASSWORD, CLIENT_ID, CLIENT_SECRET);
|
||||
|
||||
private RedditClient reddit = null;
|
||||
private SubredditReference subreddit = null;
|
||||
|
||||
private HashMap<String, PlayerData> linkCodes = new HashMap<>();
|
||||
private HashMap<PlayerData, String> pending = new HashMap<>();
|
||||
|
||||
private Map<Displayable, String> flairList = new HashMap<>();
|
||||
|
||||
private Map<Displayable, String> flairNameList = new HashMap<>();
|
||||
|
||||
private List<Displayable> noFlairDisplays = Arrays.asList(Title.VERIFIED_ADMIN, Rank.IMPOSTOR, Rank.NON_OP, Rank.OP);
|
||||
|
||||
public boolean enabled = false;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
enabled = ConfigEntry.REDDIT_CLIENT_ID.getString() == null;
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (reddit == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
reddit = OAuthHelper.automatic(new OkHttpNetworkAdapter(userAgent), credentials);
|
||||
reddit.setLogHttp(FUtil.inDeveloperMode());
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
FLog.warning("The JRAW plugin is not installed, therefore the Reddit service cannot start.");
|
||||
FLog.warning("To resolve this error, please download the latest JRAW from: https://github.com/TFPatches/Minecraft-JRAW/releases");
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
FLog.warning("Invalid Reddit credentials specified, please double check everything in the config.");
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (subreddit == null)
|
||||
{
|
||||
subreddit = reddit.subreddit(SUBREDDIT_NAME);
|
||||
}
|
||||
|
||||
loadFlairList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public void setFlair(String username, String flairID)
|
||||
{
|
||||
List<Flair> flairs = subreddit.userFlairOptions();
|
||||
Flair flair = null;
|
||||
for (Flair f : flairs)
|
||||
{
|
||||
if (f.getId().equals(flairID))
|
||||
{
|
||||
flair = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flair == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
subreddit.otherUserFlair(username).updateToTemplate(flair.getId(), "");
|
||||
}
|
||||
|
||||
public void removeFlair(String username)
|
||||
{
|
||||
subreddit.otherUserFlair(username).updateToTemplate("", "");
|
||||
}
|
||||
|
||||
public void sendModMessage(String username, String subject, String body) throws ApiException
|
||||
{
|
||||
reddit.me().inbox().compose("/r/" + SUBREDDIT_NAME, username, subject, body);
|
||||
}
|
||||
|
||||
public String addLinkCode(PlayerData data, String username)
|
||||
{
|
||||
String code = FUtil.randomAlphanumericString(10);
|
||||
linkCodes.put(code, data);
|
||||
pending.put(data, username);
|
||||
return code;
|
||||
}
|
||||
|
||||
public String checkLinkCode(String code)
|
||||
{
|
||||
PlayerData data = linkCodes.get(code);
|
||||
String username = pending.get(data);
|
||||
if (data == null || username == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
linkCodes.remove(code);
|
||||
pending.remove(data);
|
||||
|
||||
data.setRedditUsername(username);
|
||||
plugin.pl.save(data);
|
||||
|
||||
return username;
|
||||
}
|
||||
|
||||
public boolean updateFlair(Player player)
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerData data = plugin.pl.getData(player);
|
||||
String username = data.getRedditUsername();
|
||||
Displayable display = plugin.rm.getDisplay(player);
|
||||
if (username == null)
|
||||
{
|
||||
FLog.debug("No Reddit account");
|
||||
return false;
|
||||
}
|
||||
|
||||
CurrentFlair currentFlair = subreddit.otherUserFlair(username).current();
|
||||
String currentFlairName = currentFlair.getText();
|
||||
String currentFlairID = currentFlair.getId();
|
||||
String neededFlairID = flairList.get(display);
|
||||
String neededFlairName = flairNameList.get(display);
|
||||
|
||||
FLog.debug("Current ID: " + currentFlairID);
|
||||
FLog.debug("Needed ID: " + neededFlairID);
|
||||
|
||||
FLog.debug("Current Name: " + currentFlairName);
|
||||
FLog.debug("Needed Name: " + neededFlairName);
|
||||
|
||||
|
||||
// Work around
|
||||
//if (currentFlairID == null && neededFlairID != null || currentFlairID != null && neededFlairID != null && !currentFlairID.equals(neededFlairID))
|
||||
if (Strings.isNullOrEmpty(currentFlairName) && neededFlairName != null || !Strings.isNullOrEmpty(currentFlairName) && neededFlairName != null && !currentFlairName.equals(neededFlairName))
|
||||
{
|
||||
FLog.debug("Setting flair");
|
||||
setFlair(username, neededFlairID);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (noFlairDisplays.contains(display) && !Strings.isNullOrEmpty(currentFlairName))
|
||||
{
|
||||
FLog.debug("Removing flair");
|
||||
removeFlair(username);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void loadFlairList()
|
||||
{
|
||||
flairList.put(Title.OWNER, ConfigEntry.REDDIT_SERVER_OWNER_FLAIR_ID.getString());
|
||||
flairList.put(Title.EXECUTIVE, ConfigEntry.REDDIT_EXECUTIVE_FLAIR_ID.getString());
|
||||
flairList.put(Title.DEVELOPER, ConfigEntry.REDDIT_DEVELOPER_FLAIR_ID.getString());
|
||||
flairList.put(Rank.SENIOR_ADMIN, ConfigEntry.REDDIT_SENIOR_ADMIN_FLAIR_ID.getString());
|
||||
flairList.put(Rank.ADMIN, ConfigEntry.REDDIT_NEW_ADMIN_FLAIR_ID.getString());
|
||||
flairList.put(Title.MASTER_BUILDER, ConfigEntry.REDDIT_MASTER_BUILDER_FLAIR_ID.getString());
|
||||
|
||||
// Work around because the current flair ID keeps returning null, either a JRAW bug or a Reddit bug
|
||||
flairNameList.put(Title.OWNER, "Server Owner");
|
||||
flairNameList.put(Title.EXECUTIVE, "Executive");
|
||||
flairNameList.put(Title.DEVELOPER, "Developer");
|
||||
flairNameList.put(Rank.SENIOR_ADMIN, "Senior Admin");
|
||||
flairNameList.put(Rank.ADMIN, "Admin");
|
||||
flairNameList.put(Title.MASTER_BUILDER, "Master Builder");
|
||||
}
|
||||
}
|
@ -107,7 +107,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public BanManager bm;
|
||||
public IndefiniteBanList im;
|
||||
public PermissionManager pem;
|
||||
public Reddit rd;
|
||||
public GameRuleHandler gr;
|
||||
public CommandSpy cs;
|
||||
public Cager ca;
|
||||
@ -225,7 +224,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
bm = new BanManager();
|
||||
im = new IndefiniteBanList();
|
||||
pem = new PermissionManager();
|
||||
rd = new Reddit();
|
||||
gr = new GameRuleHandler();
|
||||
snp = new SignBlocker();
|
||||
ew = new EntityWiper();
|
||||
|
@ -1,69 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import net.dean.jraw.ApiException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Link your reddit account", usage = "/<command> <username | code <code>>")
|
||||
public class Command_linkreddit extends FreedomCommand
|
||||
{
|
||||
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
if (!plugin.rd.enabled)
|
||||
{
|
||||
msg("The Reddit system is currently disabled.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getData(playerSender).getRedditUsername() != null)
|
||||
{
|
||||
msg("Your Reddit account is already linked.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1 && !args[0].equals("code"))
|
||||
{
|
||||
String username = args[0];
|
||||
String code = plugin.rd.addLinkCode(getData(playerSender), username);
|
||||
|
||||
try
|
||||
{
|
||||
plugin.rd.sendModMessage(username, "Link Code", "Please run the following in-game to link your Reddit account: /linkreddit code " + code);
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
msg("Could not find a Reddit account by the name of " + args[0], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
msg("A linking code has been sent to " + username + ". Please check your mod mail at " + ChatColor.AQUA + "https://www.reddit.com/message/moderator", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
String code = args[1];
|
||||
String username = plugin.rd.checkLinkCode(code);
|
||||
|
||||
if (username == null)
|
||||
{
|
||||
msg(code + " is not a valid code", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
msg("Successfully linked the Reddit account " + username + " to your Minecraft account.", ChatColor.GREEN);
|
||||
if (plugin.rd.updateFlair(playerSender))
|
||||
{
|
||||
msg("Your flair has been updated.", ChatColor.GREEN);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Unlink your reddit account", usage = "/<command>")
|
||||
public class Command_unlinkreddit extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!plugin.rd.enabled)
|
||||
{
|
||||
msg("The reddit system is currently disabled.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerData data = getData(playerSender);
|
||||
|
||||
if (data.getRedditUsername() == null)
|
||||
{
|
||||
msg("You don't have a reddit account linked.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.rd.removeFlair(data.getRedditUsername());
|
||||
|
||||
data.setRedditUsername(null);
|
||||
plugin.pl.save(data);
|
||||
|
||||
msg("Successfully unlinked your reddit account. If you had a flair, it was removed.", ChatColor.GREEN);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -84,18 +84,6 @@ public enum ConfigEntry
|
||||
DISCORD_EXECUTIVE_ROLE_ID(String.class, "discord.executive_role_id"),
|
||||
DISCORD_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"),
|
||||
//
|
||||
REDDIT_SUBREDDIT_NAME(String.class, "reddit.subreddit_name"),
|
||||
REDDIT_USERNAME(String.class, "reddit.username"),
|
||||
REDDIT_PASSWORD(String.class, "reddit.password"),
|
||||
REDDIT_CLIENT_ID(String.class, "reddit.client_id"),
|
||||
REDDIT_CLIENT_SECRET(String.class, "reddit.client_secret"),
|
||||
REDDIT_MASTER_BUILDER_FLAIR_ID(String.class, "reddit.master_builder_flair_id"),
|
||||
REDDIT_NEW_ADMIN_FLAIR_ID(String.class, "reddit.admin_flair_id"),
|
||||
REDDIT_SENIOR_ADMIN_FLAIR_ID(String.class, "reddit.senior_admin_flair_id"),
|
||||
REDDIT_DEVELOPER_FLAIR_ID(String.class, "reddit.developer_flair_id"),
|
||||
REDDIT_EXECUTIVE_FLAIR_ID(String.class, "reddit.executive_flair_id"),
|
||||
REDDIT_SERVER_OWNER_FLAIR_ID(String.class, "reddit.server_owner_flair_id"),
|
||||
//
|
||||
PTERO_URL(String.class, "ptero.url"),
|
||||
PTERO_DEFAULT_EMAIL_DOMAIN(String.class, "ptero.default_email_domain"),
|
||||
PTERO_SERVER_UUID(String.class, "ptero.server_uuid"),
|
||||
|
@ -49,9 +49,6 @@ public class PlayerData
|
||||
private boolean displayDiscord = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private String redditUsername;
|
||||
@Getter
|
||||
@Setter
|
||||
private String loginMessage;
|
||||
@Setter
|
||||
private Boolean inspect = false;
|
||||
@ -77,7 +74,6 @@ public class PlayerData
|
||||
items.addAll(FUtil.stringToList(resultSet.getString("items")));
|
||||
totalVotes = resultSet.getInt("total_votes");
|
||||
displayDiscord = resultSet.getBoolean("display_discord");
|
||||
redditUsername = resultSet.getString("reddit_username");
|
||||
loginMessage = resultSet.getString("login_message");
|
||||
inspect = resultSet.getBoolean("inspect");
|
||||
}
|
||||
@ -115,7 +111,6 @@ public class PlayerData
|
||||
.append("- Tag: ").append(FUtil.colorize(tag)).append(ChatColor.GRAY).append("\n")
|
||||
.append("- Ride Mode: ").append(rideMode).append("\n")
|
||||
.append("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n")
|
||||
.append("- Reddit Username: ").append(redditUsername).append("\n")
|
||||
.append("- Login Message: ").append(loginMessage);
|
||||
|
||||
return output.toString();
|
||||
@ -256,7 +251,6 @@ public class PlayerData
|
||||
put("items", FUtil.listToString(items));
|
||||
put("total_votes", totalVotes);
|
||||
put("display_discord", displayDiscord);
|
||||
put("reddit_username", redditUsername);
|
||||
put("login_message", loginMessage);
|
||||
put("inspect", inspect);
|
||||
}};
|
||||
|
@ -181,7 +181,6 @@ public class RankManager extends FreedomService
|
||||
fPlayer.setTag(getTag(player, display.getColoredTag()));
|
||||
updatePlayerTeam(player);
|
||||
plugin.pem.setPermissions(player);
|
||||
plugin.rd.updateFlair(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
@ -93,7 +93,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR, `login_message` VARCHAR, `inspect` BOOLEAN NOT NULL);");
|
||||
connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `login_message` VARCHAR, `inspect` BOOLEAN NOT NULL);");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -284,7 +284,6 @@ public class SQLite extends FreedomService
|
||||
statement.setString(11, FUtil.listToString(player.getItems()));
|
||||
statement.setInt(12, player.getTotalVotes());
|
||||
statement.setBoolean(13, player.doesDisplayDiscord());
|
||||
statement.setString(14, player.getRedditUsername());
|
||||
statement.setString(15, player.getLoginMessage());
|
||||
statement.setBoolean(16, player.hasInspection());
|
||||
statement.executeUpdate();
|
||||
|
@ -80,31 +80,6 @@ discord:
|
||||
# Owner role ID
|
||||
server_owner_role_id: ''
|
||||
|
||||
# Reddit
|
||||
reddit:
|
||||
# Name of your subreddit (the r/NAME, excluding r/)
|
||||
subreddit_name: 'TotalFreedom'
|
||||
# Username of the bot account
|
||||
username: ''
|
||||
# Bot account password
|
||||
password: ''
|
||||
# Developer app id (Make one at https://www.reddit.com/prefs/apps (make sure the type is script))
|
||||
client_id: ''
|
||||
# Developer app secret
|
||||
client_secret: ''
|
||||
# Master Builder flair ID
|
||||
master_builder_flair_id: ''
|
||||
# Admin flair ID
|
||||
admin_flair_id: ''
|
||||
# Senior Admin flair ID
|
||||
senior_admin_flair_id: ''
|
||||
# Developer flair ID
|
||||
developer_flair_id: ''
|
||||
# Executive Admin flair ID
|
||||
executive_flair_id: ''
|
||||
# Owner flair ID
|
||||
server_owner_flair_id: ''
|
||||
|
||||
# Pterodactyl
|
||||
ptero:
|
||||
# URL - do not leave a trailing forward slash
|
||||
|
@ -12,7 +12,6 @@ softdepend:
|
||||
- WorldGuardExtraFlags
|
||||
- TFGuilds
|
||||
- JDA
|
||||
- JRAW
|
||||
- Votifier
|
||||
authors: [Madgeek1450, Prozza]
|
||||
api-version: "1.16"
|
Loading…
Reference in New Issue
Block a user