mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Some updates
- Added Reddit flair sync - Removed magical saddle because the stacking potato does the same thing - Some internal improvements - Fixed bug where if a service throws an error while starting or stopping it breaks the entire plugin
This commit is contained in:
parent
b73d1df350
commit
81df3103b6
8
pom.xml
8
pom.xml
@ -179,7 +179,7 @@
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.0.0_39</version>
|
||||
<version>4.2.0_168</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -254,6 +254,12 @@
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dean.jraw</groupId>
|
||||
<artifactId>JRAW</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -23,4 +23,34 @@ public class FreedomServiceHandler
|
||||
{
|
||||
return services.size();
|
||||
}
|
||||
|
||||
public void startServices()
|
||||
{
|
||||
for (FreedomService service : getServices())
|
||||
{
|
||||
try
|
||||
{
|
||||
service.onStart();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopServices()
|
||||
{
|
||||
for (FreedomService service : getServices())
|
||||
{
|
||||
try
|
||||
{
|
||||
service.onStop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@ import me.totalfreedom.totalfreedommod.permissions.PermissionManager;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||
import me.totalfreedom.totalfreedommod.reddit.Reddit;
|
||||
import me.totalfreedom.totalfreedommod.shop.Shop;
|
||||
import me.totalfreedom.totalfreedommod.shop.Votifier;
|
||||
import me.totalfreedom.totalfreedommod.sql.SQLite;
|
||||
@ -111,6 +112,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public PermbanList pm;
|
||||
public PermissionManager pem;
|
||||
public ProtectArea pa;
|
||||
public Reddit rd;
|
||||
public GameRuleHandler gr;
|
||||
public CommandSpy cs;
|
||||
public Cager ca;
|
||||
@ -229,6 +231,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
pm = new PermbanList();
|
||||
pem = new PermissionManager();
|
||||
pa = new ProtectArea();
|
||||
rd = new Reddit();
|
||||
gr = new GameRuleHandler();
|
||||
snp = new SignBlocker();
|
||||
ew = new EntityWiper();
|
||||
@ -271,10 +274,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
fab = new FAWEBridge();
|
||||
wgb = new WorldGuardBridge();
|
||||
|
||||
for (FreedomService service : fsh.getServices())
|
||||
{
|
||||
service.onStart();
|
||||
}
|
||||
fsh.startServices();
|
||||
|
||||
FLog.info("Started " + fsh.getServiceAmount() + "services.");
|
||||
|
||||
@ -301,10 +301,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public void onDisable()
|
||||
{
|
||||
// Stop services and bridges
|
||||
for (FreedomService service : fsh.getServices())
|
||||
{
|
||||
service.onStop();
|
||||
}
|
||||
fsh.stopServices();
|
||||
|
||||
getServer().getScheduler().cancelTasks(plugin);
|
||||
|
||||
|
@ -65,7 +65,6 @@ public class CommandLoader extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
FLog.debug("Loading command class " + commandClass.getSimpleName());
|
||||
add(commandClass.newInstance());
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
|
||||
@ -73,10 +72,7 @@ public class CommandLoader extends FreedomService
|
||||
FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_" , ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getCommandAmount()
|
||||
{
|
||||
return commands.size();
|
||||
FLog.info("Loaded " + commands.size() + " commands");
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
Rank level() default Rank.NON_OP;
|
||||
|
||||
SourceType source() default SourceType.BOTH;
|
||||
|
||||
|
@ -0,0 +1,69 @@
|
||||
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,29 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
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 = "Obtain a magical saddle.", usage = "/<command>")
|
||||
public class Command_magicalsaddle extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (plugin.pl.getData(playerSender).hasItem(ShopItem.MAGICAL_SADDLE))
|
||||
{
|
||||
playerSender.getInventory().addItem(plugin.sh.getMagicalSaddle());
|
||||
msg("You have been given a Magical Saddle", ChatColor.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("You do not own a Magical Saddle! Purchase one from the shop.", ChatColor.RED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -35,11 +35,9 @@ public class Command_totalfreedommod extends FreedomCommand
|
||||
}
|
||||
|
||||
plugin.config.load();
|
||||
for (FreedomService service : plugin.fsh.getServices())
|
||||
{
|
||||
service.onStop();
|
||||
service.onStart();
|
||||
}
|
||||
|
||||
plugin.fsh.stopServices();
|
||||
plugin.fsh.startServices();
|
||||
|
||||
final String message = String.format("%s v%s reloaded.",
|
||||
TotalFreedomMod.pluginName,
|
||||
|
@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -83,6 +83,21 @@ 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_DONATOR_FLAIR_ID(String.class, "reddit.donator_flair_id"),
|
||||
REDDIT_MASTER_BUILDER_FLAIR_ID(String.class, "reddit.master_builder_flair_id"),
|
||||
REDDIT_SUPER_FLAIR_ID(String.class, "reddit.super_flair_id"),
|
||||
REDDIT_TELNET_FLAIR_ID(String.class, "reddit.telnet_flair_id"),
|
||||
REDDIT_SENIOR_FLAIR_ID(String.class, "reddit.senior_flair_id"),
|
||||
REDDIT_DEVELOPER_FLAIR_ID(String.class, "reddit.developer_flair_id"),
|
||||
REDDIT_ASSISTANT_EXECUTIVE_FLAIR_ID(String.class, "reddit.assistant_executive_flair_id"),
|
||||
REDDIT_EXECUTIVE_FLAIR_ID(String.class, "reddit.executive_flair_id"),
|
||||
REDDIT_SERVER_OWNER_FLAIR_ID(String.class, "reddit.server_owner_flair_id"),
|
||||
//
|
||||
DONATION_PROBOARDS_URL(String.class, "donation.proboards_url"),
|
||||
DONATION_GROUP_ID(String.class, "donation.donator_group_id"),
|
||||
DONATION_SESSION_ID(String.class, "donation.session_id"),
|
||||
@ -103,7 +118,6 @@ public enum ConfigEntry
|
||||
SHOP_PRICES_RIDEABLE_PEARL(Integer.class, "shop.prices.rideable_pearl"),
|
||||
SHOP_PRICES_STACKING_POTATO(Integer.class, "shop.prices.stacking_potato"),
|
||||
SHOP_PRICES_CLOWN_FISH(Integer.class, "shop.prices.clown_fish"),
|
||||
SHOP_PRICES_MAGICAL_SADDLE(Integer.class, "shop.prices.magical_saddle"),
|
||||
//
|
||||
ADMINLIST_CLEAN_THESHOLD_HOURS(Integer.class, "adminlist.clean_threshold_hours"),
|
||||
ADMINLIST_CONSOLE_IS_SENIOR(Boolean.class, "adminlist.console_is_senior"),
|
||||
|
@ -104,7 +104,7 @@ public class Discord extends FreedomService
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
FLog.warning("The JDA plugin is not installed, therefore the bot cannot start.");
|
||||
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/TFPatches/Minecraft-JDA/releases");
|
||||
}
|
||||
|
||||
|
@ -107,29 +107,14 @@ public class ItemFun extends FreedomService
|
||||
|
||||
if (player.getInventory().getItemInMainHand().getType().equals(Material.POTATO) || entity.getType().equals(EntityType.PLAYER))
|
||||
{
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.STACKING_POTATO, player.getInventory().getItemInMainHand(), plugin.sh.getStackingPotato()))
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.STACKING_POTATO, player.getInventory(), plugin.sh.getStackingPotato()))
|
||||
{
|
||||
player.addPassenger(entity);
|
||||
player.sendMessage("Stacked " + entity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (onCooldown(player, ShopItem.MAGICAL_SADDLE))
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "You're currently on a cool-down for 15 seconds.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getInventory().getItemInMainHand().getType().equals(Material.SADDLE) || player.getInventory().getItemInOffHand().getType().equals(Material.SADDLE) || entity.getType().equals(EntityType.PLAYER))
|
||||
{
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.MAGICAL_SADDLE, player.getInventory().getItemInMainHand(), plugin.sh.getMagicalSaddle()) || plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.MAGICAL_SADDLE, player.getInventory().getItemInOffHand(), plugin.sh.getMagicalSaddle()))
|
||||
{
|
||||
entity.addPassenger(player);
|
||||
cooldown(player, ShopItem.MAGICAL_SADDLE, 15);
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
entity.sendMessage(ChatColor.GRAY + player.getName() + " is now riding you, run /eject to eject them.");
|
||||
return;
|
||||
}
|
||||
player.addPassenger(entity);
|
||||
player.sendMessage("Stacked " + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,7 +137,7 @@ public class ItemFun extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.STACKING_POTATO, player.getInventory().getItemInMainHand(), plugin.sh.getStackingPotato()))
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.STACKING_POTATO, player.getInventory(), plugin.sh.getStackingPotato()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -215,7 +200,7 @@ public class ItemFun extends FreedomService
|
||||
|
||||
case BLAZE_ROD:
|
||||
{
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.LIGHTNING_ROD, player.getInventory().getItemInMainHand(), plugin.sh.getLightningRod()))
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.LIGHTNING_ROD, player.getInventory(), plugin.sh.getLightningRod()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -239,7 +224,7 @@ public class ItemFun extends FreedomService
|
||||
|
||||
case FIRE_CHARGE:
|
||||
{
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.FIRE_BALL, player.getInventory().getItemInMainHand(), plugin.sh.getFireBall()))
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.FIRE_BALL, player.getInventory(), plugin.sh.getFireBall()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -263,7 +248,7 @@ public class ItemFun extends FreedomService
|
||||
final int RADIUS_HIT = 5;
|
||||
final int STRENGTH = 4;
|
||||
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.CLOWN_FISH, player.getInventory().getItemInMainHand(), plugin.sh.getClownFish()))
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.CLOWN_FISH, player.getInventory(), plugin.sh.getClownFish()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -329,7 +314,7 @@ public class ItemFun extends FreedomService
|
||||
if (entity instanceof EnderPearl && entity.getShooter() instanceof Player)
|
||||
{
|
||||
Player player = (Player)entity.getShooter();
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.RIDEABLE_PEARL, player.getInventory().getItemInMainHand(), plugin.sh.getRideablePearl()))
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.RIDEABLE_PEARL, player.getInventory(), plugin.sh.getRideablePearl()))
|
||||
{
|
||||
entity.addPassenger(player);
|
||||
}
|
||||
@ -390,7 +375,7 @@ public class ItemFun extends FreedomService
|
||||
PlayerData data = plugin.pl.getData(player);
|
||||
PlayerInventory inv = event.getPlayer().getInventory();
|
||||
ItemStack rod = inv.getItemInMainHand();
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.GRAPPLING_HOOK, player.getInventory().getItemInMainHand(), plugin.sh.getGrapplingHook()))
|
||||
if (plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.GRAPPLING_HOOK, player.getInventory(), plugin.sh.getGrapplingHook()))
|
||||
{
|
||||
if (event.getState() == PlayerFishEvent.State.REEL_IN || event.getState() == PlayerFishEvent.State.IN_GROUND)
|
||||
{
|
||||
|
@ -50,6 +50,9 @@ public class PlayerData
|
||||
private int totalVotes;
|
||||
@Setter
|
||||
private boolean displayDiscord = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private String redditUsername;
|
||||
|
||||
public PlayerData(ResultSet resultSet)
|
||||
{
|
||||
@ -73,6 +76,7 @@ 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");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -108,7 +112,8 @@ public class PlayerData
|
||||
.append("- Display Discord: ").append(displayDiscord).append("\n")
|
||||
.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("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n")
|
||||
.append("- Reddit Username: ").append(redditUsername);
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
@ -244,6 +249,7 @@ public class PlayerData
|
||||
put("items", FUtil.listToString(items));
|
||||
put("total_votes", totalVotes);
|
||||
put("display_discord", displayDiscord);
|
||||
put("reddit_username", redditUsername);
|
||||
}};
|
||||
return map;
|
||||
}
|
||||
|
@ -178,15 +178,7 @@ public class PlayerList extends FreedomService
|
||||
|
||||
if (plugin.al.isAdminImpostor(player))
|
||||
{
|
||||
Admin admin = null;
|
||||
for (Admin loopAdmin : plugin.al.getAllAdmins())
|
||||
{
|
||||
if (loopAdmin.getName().equalsIgnoreCase(player.getName()))
|
||||
{
|
||||
admin = loopAdmin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Admin admin = plugin.al.getEntryByName(player.getName());
|
||||
admin.setLastLogin(new Date());
|
||||
admin.addIp(FUtil.getIp(player));
|
||||
plugin.al.updateTables();
|
||||
|
@ -192,6 +192,7 @@ 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)
|
||||
|
226
src/main/java/me/totalfreedom/totalfreedommod/reddit/Reddit.java
Normal file
226
src/main/java/me/totalfreedom/totalfreedommod/reddit/Reddit.java
Normal file
@ -0,0 +1,226 @@
|
||||
package me.totalfreedom.totalfreedommod.reddit;
|
||||
|
||||
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.FreedomService;
|
||||
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", plugin.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 = !Strings.isNullOrEmpty(ConfigEntry.REDDIT_CLIENT_ID.getString());
|
||||
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.randomString(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.ASSISTANT_EXECUTIVE, ConfigEntry.REDDIT_ASSISTANT_EXECUTIVE_FLAIR_ID.getString());
|
||||
flairList.put(Title.DEVELOPER, ConfigEntry.REDDIT_DEVELOPER_FLAIR_ID.getString());
|
||||
flairList.put(Rank.SENIOR_ADMIN, ConfigEntry.REDDIT_SENIOR_FLAIR_ID.getString());
|
||||
flairList.put(Rank.TELNET_ADMIN, ConfigEntry.REDDIT_TELNET_FLAIR_ID.getString());
|
||||
flairList.put(Rank.SUPER_ADMIN, ConfigEntry.REDDIT_SUPER_FLAIR_ID.getString());
|
||||
flairList.put(Title.MASTER_BUILDER, ConfigEntry.REDDIT_MASTER_BUILDER_FLAIR_ID.getString());
|
||||
flairList.put(Title.DONATOR, ConfigEntry.REDDIT_DONATOR_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.ASSISTANT_EXECUTIVE, "Assistant Executive");
|
||||
flairNameList.put(Title.DEVELOPER, "Developer");
|
||||
flairNameList.put(Rank.SENIOR_ADMIN, "Senior Admin");
|
||||
flairNameList.put(Rank.TELNET_ADMIN, "Telnet Admin");
|
||||
flairNameList.put(Rank.SUPER_ADMIN, "Super Admin");
|
||||
flairNameList.put(Title.MASTER_BUILDER, "Master Builder");
|
||||
flairNameList.put(Title.DONATOR, "Premium");
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -168,6 +169,16 @@ public class Shop extends FreedomService
|
||||
return gui;
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem)
|
||||
{
|
||||
if (isRealItem(data, shopItem, inventory.getItemInMainHand(), realItem) || isRealItem(data, shopItem, inventory.getItemInOffHand(), realItem))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem)
|
||||
{
|
||||
if (!data.hasItem(shopItem) || !givenItem.getType().equals(realItem.getType()))
|
||||
|
@ -12,18 +12,17 @@ public enum ShopItem
|
||||
FIRE_BALL("Fire Ball", Material.FIRE_CHARGE, 14, ConfigEntry.SHOP_PRICES_FIRE_BALL, ChatColor.RED, "fireBall", "/fireball"),
|
||||
RIDEABLE_PEARL("Rideable Ender Pearl", Material.ENDER_PEARL, 16, ConfigEntry.SHOP_PRICES_RIDEABLE_PEARL, ChatColor.DARK_PURPLE, "rideablePearl", "/rideablepearl"),
|
||||
STACKING_POTATO("Stacking Potato", Material.POTATO, 20, ConfigEntry.SHOP_PRICES_STACKING_POTATO, ChatColor.YELLOW, "stackingPotato", "/stackingpotato"),
|
||||
MAGICAL_SADDLE("Magical Saddle", Material.SADDLE, 22, ConfigEntry.SHOP_PRICES_MAGICAL_SADDLE, ChatColor.DARK_GREEN, "magicalSaddle", "/magicalsaddle"),
|
||||
CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 24, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish");
|
||||
|
||||
/*
|
||||
Shop GUI Layout:
|
||||
|
||||
Dimensions: 9x4 = 36
|
||||
Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, s = Stacking Potato, c = Clown Fish, m = Magical Saddle $ = Coins}
|
||||
Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, s = Stacking Potato, c = Clown Fish, $ = Coins}
|
||||
|
||||
---------
|
||||
-g-l-f-r-
|
||||
--s-m-c--
|
||||
--s---c--
|
||||
--------$
|
||||
*/
|
||||
|
||||
|
@ -43,7 +43,6 @@ public class SQLite extends FreedomService
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to connect to the database: " + e.getMessage());
|
||||
FLog.info("Successfully disconnected from the database.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.createStatement().execute("CREATE TABLE `admins` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `login_message` VARCHAR, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `old_tags` BOOLEAN NOT NULL, `log_stick` BOOLEAN NOT NULL, `display_discord` BOOLEAN NOT NULL);");
|
||||
connection.createStatement().execute("CREATE TABLE `admins` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `login_message` VARCHAR, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `old_tags` BOOLEAN NOT NULL, `log_stick` BOOLEAN NOT NULL);");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -94,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, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT 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, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR NOT NULL);");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -271,7 +270,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, FUtil.listToString(player.getIps()));
|
||||
statement.setString(3, FUtil.listToString(player.getNotes()));
|
||||
@ -286,6 +285,7 @@ public class SQLite extends FreedomService
|
||||
statement.setString(12, FUtil.listToString(player.getItems()));
|
||||
statement.setInt(13, player.getTotalVotes());
|
||||
statement.setBoolean(14, player.doesDisplayDiscord());
|
||||
statement.setString(15, player.getRedditUsername());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
@ -84,6 +84,37 @@ 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: ''
|
||||
# Donator flair ID
|
||||
donator_flair_id: ''
|
||||
# Master Builder flair ID
|
||||
master_builder_flair_id: ''
|
||||
# Super Admin flair ID
|
||||
super_flair_id: ''
|
||||
# Telnet Admin flair ID
|
||||
telnet_flair_id: ''
|
||||
# Senior Admin flair ID
|
||||
senior_flair_id: ''
|
||||
# Developer flair ID
|
||||
developer_flair_id: ''
|
||||
# Assistant Executive Admin flair ID
|
||||
assistant_executive_flair_id: ''
|
||||
# Executive Admin flair ID
|
||||
executive_flair_id: ''
|
||||
# Owner flair ID
|
||||
server_owner_flair_id: ''
|
||||
|
||||
# The shop
|
||||
shop:
|
||||
# Enable the shop
|
||||
@ -124,7 +155,6 @@ shop:
|
||||
rideable_pearl: 700
|
||||
stacking_potato: 300
|
||||
clown_fish: 1500
|
||||
magical_saddle: 250
|
||||
|
||||
# Admin list
|
||||
adminlist:
|
||||
|
Loading…
Reference in New Issue
Block a user