mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-30 13:27:37 +00:00
Merge branch 'development' into FS-37
This commit is contained in:
commit
8cbfde8bbc
@ -1,98 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME;
|
||||
|
||||
public class SavedFlags extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Boolean> getSavedFlags()
|
||||
{
|
||||
Map<String, Boolean> flags = null;
|
||||
File input = new File(TotalFreedomMod.getPlugin().getDataFolder(), SAVED_FLAGS_FILENAME);
|
||||
|
||||
if (input.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
try (FileInputStream fis = new FileInputStream(input); ObjectInputStream ois = new ObjectInputStream(fis))
|
||||
{
|
||||
flags = (HashMap<String, Boolean>)ois.readObject();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public boolean getSavedFlag(String flag) throws Exception
|
||||
{
|
||||
Boolean flagValue = null;
|
||||
|
||||
Map<String, Boolean> flags = getSavedFlags();
|
||||
|
||||
if (flags != null)
|
||||
{
|
||||
if (flags.containsKey(flag))
|
||||
{
|
||||
flagValue = flags.get(flag);
|
||||
}
|
||||
}
|
||||
|
||||
if (flagValue != null)
|
||||
{
|
||||
return flagValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSavedFlag(String flag, boolean value)
|
||||
{
|
||||
Map<String, Boolean> flags = getSavedFlags();
|
||||
|
||||
if (flags == null)
|
||||
{
|
||||
flags = new HashMap<>();
|
||||
}
|
||||
|
||||
flags.put(flag, value);
|
||||
|
||||
try
|
||||
{
|
||||
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(flags);
|
||||
oos.close();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -75,7 +75,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public CommandLoader cl;
|
||||
// Services
|
||||
public ServerInterface si;
|
||||
public SavedFlags sf;
|
||||
public WorldManager wm;
|
||||
public LogViewer lv;
|
||||
public AdminList al;
|
||||
@ -298,7 +297,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
{
|
||||
// Start services
|
||||
si = new ServerInterface();
|
||||
sf = new SavedFlags();
|
||||
wm = new WorldManager();
|
||||
lv = new LogViewer();
|
||||
sql = new SQLite();
|
||||
|
@ -192,7 +192,6 @@ public class CoreProtectBridge extends FreedomService
|
||||
return (megabytes / 1024);
|
||||
}
|
||||
|
||||
// Wipes DB for the specified world
|
||||
public void clearDatabase(World world)
|
||||
{
|
||||
clearDatabase(world, false);
|
||||
@ -260,12 +259,6 @@ public class CoreProtectBridge extends FreedomService
|
||||
{
|
||||
FLog.warning("Failed to delete the CoreProtect data for the " + world.getName());
|
||||
}
|
||||
|
||||
// This exits for flatlands wipes
|
||||
if (shutdown)
|
||||
{
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
@ -86,6 +86,7 @@ public enum ConfigEntry
|
||||
DISCORD_ASSISTANT_EXECUTIVE_ROLE_ID(String.class, "discord.assistant_executive_role_id"),
|
||||
DISCORD_EXECUTIVE_ROLE_ID(String.class, "discord.executive_role_id"),
|
||||
DISCORD_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"),
|
||||
DISCORD_INVITE_LINK(String.class, "discord.invite_link"),
|
||||
//
|
||||
PTERO_URL(String.class, "ptero.url"),
|
||||
PTERO_DEFAULT_EMAIL_DOMAIN(String.class, "ptero.default_email_domain"),
|
||||
|
@ -10,9 +10,12 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -28,39 +31,66 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
{
|
||||
Member member = event.getMember();
|
||||
String tag = getDisplay(member);
|
||||
StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]");
|
||||
Message msg = event.getMessage();
|
||||
|
||||
ComponentBuilder emsg = new ComponentBuilder();
|
||||
|
||||
// Prefix
|
||||
emsg.append(ChatColor.DARK_GRAY + "[");
|
||||
TextComponent inviteLink = new TextComponent("Discord");
|
||||
inviteLink.setColor(ChatColor.DARK_AQUA.asBungee());
|
||||
inviteLink.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Click here to get the invite link!")));
|
||||
inviteLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
|
||||
ConfigEntry.DISCORD_INVITE_LINK.getString()));
|
||||
emsg.append(inviteLink);
|
||||
emsg.append(ChatColor.DARK_GRAY + "] ", ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Tag (if they have one)
|
||||
if (tag != null)
|
||||
{
|
||||
message.append(" ").append(tag);
|
||||
}
|
||||
message.append(" ").append(ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET);
|
||||
ComponentBuilder builder = new ComponentBuilder(message.toString());
|
||||
if (!msg.getContentDisplay().isEmpty())
|
||||
{
|
||||
builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay()));
|
||||
message.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); // for logging
|
||||
emsg.append(tag);
|
||||
}
|
||||
|
||||
emsg.append(" ");
|
||||
|
||||
// User
|
||||
TextComponent user = new TextComponent(ChatColor.stripColor(member.getEffectiveName()));
|
||||
user.setColor(ChatColor.RED.asBungee());
|
||||
emsg.append(user);
|
||||
|
||||
// Message
|
||||
emsg.append(ChatColor.DARK_GRAY + ": " + ChatColor.RESET
|
||||
+ ChatColor.stripColor(msg.getContentDisplay()), ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Attachments
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
{
|
||||
if (!msg.getContentDisplay().isEmpty())
|
||||
emsg.append(" ");
|
||||
|
||||
for (Message.Attachment attachment : msg.getAttachments())
|
||||
{
|
||||
attachment.getUrl();
|
||||
builder.append(" ");
|
||||
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
|
||||
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
builder.append(text);
|
||||
message.append(" [Media]"); // for logging
|
||||
TextComponent media = new TextComponent("[Media] ");
|
||||
media.setColor(ChatColor.YELLOW.asBungee());
|
||||
media.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
media.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(attachment.getUrl())));
|
||||
|
||||
emsg.append(media, ComponentBuilder.FormatRetention.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] components = emsg.create();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
|
||||
{
|
||||
player.spigot().sendMessage(builder.create());
|
||||
player.spigot().sendMessage(components);
|
||||
}
|
||||
}
|
||||
FLog.info(message.toString());
|
||||
|
||||
FLog.info(TextComponent.toLegacyText(components), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
public class FUtil
|
||||
{
|
||||
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
/* See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
||||
Leaving this list here for anyone running TFM on a cracked server:
|
||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "Telesphoreo", "CoolJWB");
|
||||
|
@ -1,9 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -32,8 +29,6 @@ public class Flatlands extends CustomWorld
|
||||
return null;
|
||||
}
|
||||
|
||||
wipeFlatlandsIfFlagged();
|
||||
|
||||
final WorldCreator worldCreator = new WorldCreator(getName());
|
||||
worldCreator.generateStructures(false);
|
||||
worldCreator.type(WorldType.NORMAL);
|
||||
@ -63,32 +58,4 @@ public class Flatlands extends CustomWorld
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
public void wipeFlatlandsIfFlagged()
|
||||
{
|
||||
boolean doFlatlandsWipe = false;
|
||||
try
|
||||
{
|
||||
doFlatlandsWipe = plugin.sf.getSavedFlag("do_wipe_flatlands");
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
|
||||
if (doFlatlandsWipe)
|
||||
{
|
||||
if (Bukkit.getServer().getWorld("flatlands") == null)
|
||||
{
|
||||
FLog.info("Wiping flatlands.");
|
||||
plugin.sf.setSavedFlag("do_wipe_flatlands", false);
|
||||
FileUtils.deleteQuietly(new File("./flatlands"));
|
||||
}
|
||||
else
|
||||
{
|
||||
FLog.severe("Can't wipe flatlands, it is already loaded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ discord:
|
||||
executive_role_id: ''
|
||||
# Owner role ID
|
||||
server_owner_role_id: ''
|
||||
# Invite link for your Discord server
|
||||
invite_link: 'https://discord.com/invite/PW4savJR9a'
|
||||
|
||||
# Pterodactyl
|
||||
ptero:
|
||||
|
Loading…
Reference in New Issue
Block a user